import axios from 'axios'
import {appId, httptimeout} from '@/config/env'

/**
 * [description]
 * @param  {[type]} uri    [description]
 * @param  {[type]} method [description]
 * @param  {[type]} params [description]
 * @return {[type]}        [description]
 */
export const apiAsyncSnd2Acct = async (uri, method, params) => {
  console.log("apiAsyncSnd2Acct:", method, params);
  if (method === "get") {
    return axios.get(uri, {params: params});
  } else {
    return axios.post(uri, params);
  }
}

/**
 * [同步发送账户服务请求]
 * @param  {[string-utf-8]} data [待签名数据]
 * @return {[jsonobj]}      [description]
 */
export const apiSnd2Acct = async (uri, method, params) => {
  console.log("apiSnd2Acct:", method, params);

  let rsp = {};
  try {
    if (method === "get") {
      rsp = await axios.get(uri, {params: params});
    } else {
      rsp = await axios.post(uri, params);
    }
  }
  catch(e) {
    console.warn('exp:', e);
    rsp.data = {};
    rsp.data.errno = -1;
    rsp.data.errmsg = "业务超时请重试-apiGetSign";
    rsp.data.sysmsg = e.code + ":" + e.message;
    console.warn("rsp.data:", rsp.data);
  }
  return rsp.data;
}

/**
 * []
 * @param  {[type]} params [description]
 * @return {[type]}      [description]
 */
export const apiGetUserAcct = async (params) => {
  console.log("apiGetUserAcct-params:", params);
  let uri = "/acct/accttxn_queryam";
  return axios.post(uri, params);
}


